package cn.kgc.houseservice.service;


import cn.kgc.bean.Room;
import cn.kgc.myhousemapper.mapper.RoomMapper;
import cn.kgc.service.RoomService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class RoomServiceImpl implements RoomService {
    @Resource
    RoomMapper roomMapper;

    @Override
    public Room selectRoomById(Integer id) {
        return roomMapper.selectById(id);
    }

    @Override
    public int updateRoom(Room room) {
        return roomMapper.updateById(room);
    }

    @Override
    public PageInfo<Room> selectRoomByHouseInfo(Integer pageNum,Integer pageSize,Integer houseid, String roomname) {
        PageHelper.startPage(pageNum,pageSize);
/*        RoomExample roomExample=new RoomExample();
        RoomExample.Criteria roomExampleCriteria = roomExample.createCriteria();*/
        QueryWrapper<Room> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("houseid",houseid);
        if (roomname!=null&&!roomname.equals("")){
            queryWrapper.like("roomname",roomname);
        }
        List<Room> rooms = roomMapper.selectList(queryWrapper);
        PageInfo<Room> pageInfo=new PageInfo<>(rooms);
        return pageInfo;
    }

    @Override
    public int deleteRoomById(Integer id) {
        int i = roomMapper.deleteById(id);
        return i;
    }
}
